package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.AdministerRoleDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 角色服务
 */

@Service(interfaceClass = AdministerRoleService.class)
@Transactional
public class AdministerRoleServiceImpl implements AdministerRoleService {

    @Autowired
    private AdministerRoleDao administerRoleDao;

    //新增角色
    @Override
    public void add(Role role) {
        //新增角色
        administerRoleDao.add(role);
    }

    //分页查询
    @Override
    public PageResult findPage(QueryPageBean pageBean) {
        Integer currentPage = pageBean.getCurrentPage();
        Integer pageSize = pageBean.getPageSize();
        String queryString = pageBean.getQueryString();
        //使用分页助手插件实现分页查询
        PageHelper.startPage(currentPage,pageSize);
        Page<Role> page = administerRoleDao.findByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    //编辑检查项信息
    @Override
    public void edit(Role role) {
        //基本信息修改
        administerRoleDao.edit(role);
    }

    //根据id查找
    @Override
    public Role findById(Integer id) {
        return administerRoleDao.findById(id);
    }

    @Override
    public List<Role> findAll() {
        return administerRoleDao.findAll();
    }

    @Override
    public void delete(Integer id) {
        administerRoleDao.delete(id);
    }
}
